﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtAspNet;

namespace HY.WEB.Controls
{
    public partial class main : System.Web.UI.UserControl
    {
        public string am1,am2,pm1,pm2;
        public string whe = "", stype = "";
        public string us, nm;
        protected void Page_Load(object sender, EventArgs e)
        {
            us = Session["ID"].ToString();
            nm = Session["user"].ToString();
          
            load_time();
            fill_info();
            
        }

        void load_time()
        {
                Calendar1.MinDate = DateTime.Now.AddDays(-30);
                Calendar1.MaxDate = DateTime.Now.AddDays(30);
                DataTable d = BLL.Bllbase.get_table("hr_kq_set");
            
                am1 = d.Rows[0]["ams"].ToString();
                am2 = d.Rows[0]["ame"].ToString();
               
                pm1 = d.Rows[0]["pms"].ToString();
                pm2 = d.Rows[0]["pme"].ToString();

                lbltime1.Text = "上班时间：" + am1;
                lbltime2.Text = "下班时间：" + am2;
                lbltime3.Text = "上班时间：" + pm1;
                lbltime4.Text = "下班时间：" + pm2;
        }

        protected void btkq_Click(object sender, EventArgs e)
        {
            string us=Session["user"].ToString();
            string bh= Session["bh"].ToString();
            string sty = "非工作时间";
            DateTime tt = DateTime.Now;
            tt =DateTime.Parse(tt.ToString("yyyy-MM-dd HH:mm")); //24

            string ss = tt.Hour.ToString();

            if (float.Parse(ss) > 7 & float.Parse(ss) < 10) 
                sty ="上午-上班"+BLL.BLLfun.gettimetype("上班",tt, am1);
              
            if (float.Parse(ss) > 11 & float.Parse(ss) < 13)
                sty = "上午-下班" + BLL.BLLfun.gettimetype("下班", tt, am2);
                
        
            if (float.Parse(ss) > 13 & float.Parse(ss) < 15)
                sty = "下午-上班" + BLL.BLLfun.gettimetype("上班", tt, pm1);

            if (float.Parse(ss) > 15 & float.Parse(ss) < 20)
                sty = "下午-下班" + BLL.BLLfun.gettimetype("下班", tt, pm2);

                 
            string sqltxt = "insert into hr_kq values('" + bh +
                                                   "','" + us +
                                                    "',getdate(),'" + 
                                                       sty + "',0)";

            DAL.DbHelperSQL.ExecuteNonQuery(sqltxt);
            Alert.Show("考勤成功,结果是：" + sty+" (请注意在上下班前后两个小时以内打卡，否则视为无效考勤!)");
            
        }

        void fill_info()
        {
            string us = Session["ID"].ToString();
            string um = Session["user"].ToString();

            DataTable table = BLL.oa.ad.get_list_top("AD");   //公司制度
            Grid1.DataSource = table;
            Grid1.DataBind();


            DataTable table2 = BLL.msg.msgbase.get_list_top(us, "1", "", nm);  
            Grid2.DataSource = table2;
            Grid2.DataBind();

            DataTable table3 = BLL.oa.task.get_list_y_top(us, "");
            Grid3.DataSource = table3;
            Grid3.DataBind();

            DataTable table4 = BLL.oa.ad.get_list_top("MM");   //公司制度
            Grid4.DataSource = table4;
            Grid4.DataBind();

            DataTable table5 = BLL.oa.ad.get_list_top("PP"); //文摘
            Grid5.DataSource = table5;
            Grid5.DataBind();

        }

        protected void Grid1_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
        }


        protected void Grid2_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Grid2.PageIndex = e.NewPageIndex;
        }

        protected void Grid3_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Grid3.PageIndex = e.NewPageIndex;
        }

        protected void Grid4_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Grid4.PageIndex = e.NewPageIndex;
        }

        protected void Grid5_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Grid5.PageIndex = e.NewPageIndex;
        }

    }
}